package com.yanqu.road.logic.activity.yqhotel;

import com.yanqu.road.dao.impl.activity.yqhotel.YQHotelConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.yqhotel.config.*;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class YQHotelConfig {

    private ActivityInfo activityInfo;

    private int activityId;

    private Map<Integer, Map<Integer, YqHotelSkillConfig>> skillConfigMap;
    private Map<Integer, Map<Integer, YqHotelCounterConfig>> counterConfigMap;
    private Map<Integer, YqHotelTitleConfig> titleConfigMap;
    private Map<Integer, YqHotelBeastConfig> beastConfigMap;
    private Map<Integer, YqHotelEventConfig> eventConfigMap;
    private List<YqHotelFoodNameConfig> foodNameConfigList;


    //学院建筑时间表 编号，进去时间毫秒，开始时间到进去的经过时间（不用等待的进入时间）
    private Map<Integer,Long> buildingEnterTimeMap = new ConcurrentHashMap<>();

    //学院建筑时间表 编号，学习时间毫秒，学习持续的经过时间
    private Map<Integer,Long> buildingStudyTimeMap = new ConcurrentHashMap<>();

    //学院建筑座位表 编号，等级对应多少个坑位
    private Map<Integer,Map<Integer,Integer>> buildingSeatMap = new ConcurrentHashMap<>();

    //招生办建筑id
    private int enrolBuildingId = 1;

    //魂力检测建筑id
    private int soulCheckBuildingId = 2;

    //积分道具
    private int YQHOTEL_SCORE_ITEM_ID = 101718;
    //惊魂币
    private int YQHOTEL_COST_NUM_ID = 124308;

    //排队人数
    private String YQHOTEL_QUEUE_NUM = "4|4|5|5|5|5|5";
    private List<Integer> yqHotelQueueNum = new ArrayList<>();


    private Map<Integer,Long> processTimeMap;
    //各个学院处理时间/s（招生办|武魂检测|辅助系|敏攻系|食物系|远攻系|强攻系）
    private String YQHOTEL_PROCESS_TIME = "60000|50000|40000|80000|90000|70000|50000";

    private Map<Integer,Long> walkTimeMap;
    //各学院间走路时间/s（门口|招生办|武魂检测|辅助系|敏攻系|食物系|远攻系|强攻系）
    private String YQHOTEL_WALK_TIME = "5000|4000|3000|6000|7000|4000|5000";

    //柜台解锁时间/s
    private long YQHOTEL_COUNTER_UNLOCK_TIME = 5 * 1000;

    //武魂的种类个数
    private int YQHOTEL_SKILL_NAME_NUM = 100;

    //事件刷新时间
    private long YQHOTEL_EVENT_REFRESH_TIME = 6*60*60*1000;

    private long YQHOTEL_BATTLE_QUICK_OPEN_LIMIT = 5000;

    public YQHotelConfig(ActivityInfo tmpactivityInfo, Map<String, ActivityConfig> activityConfigMap) {

        activityInfo = tmpactivityInfo;
        activityId = tmpactivityInfo.getActivityId();

        Map<Integer, Map<Integer, YqHotelSkillConfig>> tmpYQHotelSkillConfigMap = new YQHotelConfigDaoImpl().getYQHotelSkillConfigMap(activityId);
        Map<Integer, Map<Integer, YqHotelCounterConfig>> tmpYQHotelCounterConfigMap = new YQHotelConfigDaoImpl().getYQHotelCounterConfigMap(activityId);
        Map<Integer, YqHotelTitleConfig> tmpYQHotelTitleConfigMap = new YQHotelConfigDaoImpl().getYQHotelTitleConfigMap(activityId);
        Map<Integer, YqHotelBeastConfig> tmpYQHotelBeastConfigMap = new YQHotelConfigDaoImpl().getYQHotelBeastConfigMap(activityId);
        Map<Integer, YqHotelEventConfig> tmpYQHotelEventConfigMap = new YQHotelConfigDaoImpl().getYQHotelEventConfigMap(activityId);
        List<YqHotelFoodNameConfig> tmpNameConfigList = new YQHotelConfigDaoImpl().getYqHotelFoodNameConfigList(activityId);

        if(activityConfigMap != null){
            if(activityConfigMap.containsKey("YQHOTEL_SCORE_ITEM_ID")){
                YQHOTEL_SCORE_ITEM_ID = activityConfigMap.get("YQHOTEL_SCORE_ITEM_ID").getIntValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_COST_NUM_ID")){
                YQHOTEL_COST_NUM_ID = activityConfigMap.get("YQHOTEL_COST_NUM_ID").getIntValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_QUEUE_NUM")){
                YQHOTEL_QUEUE_NUM = activityConfigMap.get("YQHOTEL_QUEUE_NUM").getValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_PROCESS_TIME")){
                YQHOTEL_PROCESS_TIME = activityConfigMap.get("YQHOTEL_PROCESS_TIME").getValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_WALK_TIME")){
                YQHOTEL_WALK_TIME = activityConfigMap.get("YQHOTEL_WALK_TIME").getValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_COUNTER_UNLOCK_TIME")){
                YQHOTEL_COUNTER_UNLOCK_TIME = activityConfigMap.get("YQHOTEL_COUNTER_UNLOCK_TIME").getLongValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_SKILL_NAME_NUM")){
                YQHOTEL_SKILL_NAME_NUM = activityConfigMap.get("YQHOTEL_SKILL_NAME_NUM").getIntValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_EVENT_REFRESH_TIME")){
                YQHOTEL_EVENT_REFRESH_TIME = activityConfigMap.get("YQHOTEL_EVENT_REFRESH_TIME").getIntValue();
            }
            if(activityConfigMap.containsKey("YQHOTEL_BATTLE_QUICK_OPEN_LIMIT")){
                YQHOTEL_BATTLE_QUICK_OPEN_LIMIT = activityConfigMap.get("YQHOTEL_BATTLE_QUICK_OPEN_LIMIT").getLongValue();
            }

            processTimeMap = new ConcurrentHashMap<>();
            List<Long> processTimeList = StringUtils.stringToLongList(YQHOTEL_PROCESS_TIME, "\\|");
            for(int i = 0 ; i < processTimeList.size() ; i++){
                processTimeMap.put(i+1,processTimeList.get(i));
            }

            walkTimeMap = new ConcurrentHashMap<>();
            List<Long> walkTimeList = StringUtils.stringToLongList(YQHOTEL_WALK_TIME, "\\|");
            for(int i = 0 ; i < processTimeList.size() ; i++){
                walkTimeMap.put(i+1,walkTimeList.get(i));
            }
        }
        Map<Integer,Long> tempBuildingStudyTimeMap = new ConcurrentHashMap<>();
        Map<Integer,Long> tempBuildingEnterTimeMap = new ConcurrentHashMap<>();

        long totalTime = 0L;
        for(int buildingId : processTimeMap.keySet()){
            tempBuildingStudyTimeMap.put(buildingId,processTimeMap.get(buildingId));
            if(walkTimeMap.containsKey(buildingId)){
                totalTime += walkTimeMap.get(buildingId);
            }
            if(processTimeMap.containsKey(buildingId-1)){
                totalTime += processTimeMap.get(buildingId-1);
            }
            tempBuildingEnterTimeMap.put(buildingId,totalTime);
        }

        Map<Integer,Map<Integer,Integer>> tempBuildingSeatMap = new ConcurrentHashMap<>();
        for(int buildingId : tmpYQHotelCounterConfigMap.keySet()){
            tempBuildingSeatMap.put(buildingId,new ConcurrentHashMap<>());
            for(YqHotelCounterConfig counterConfig : tmpYQHotelCounterConfigMap.get(buildingId).values()){
                tempBuildingSeatMap.get(buildingId).put(counterConfig.getLevel(),counterConfig.getNum());
            }
        }

        for(YqHotelTitleConfig titleConfig : tmpYQHotelTitleConfigMap.values()){
            List<Long> soulRangeList =  StringUtils.stringToLongList(titleConfig.getSourPower(),",");
            titleConfig.setSmallValue(soulRangeList.get(0));
            titleConfig.setBigValue(soulRangeList.get(1));
        }

        for(YqHotelBeastConfig beastConfig : tmpYQHotelBeastConfigMap.values()){
            List<BigInteger> paramsList =  StringUtils.stringToBigIntegerList(beastConfig.getSourPower(),",");
            beastConfig.setBlood(paramsList.get(0));
            beastConfig.setKillTimes(paramsList.get(1).intValue());
        }

        for(YqHotelEventConfig eventConfig : tmpYQHotelEventConfigMap.values()){
            List<String> rewardList =  StringUtils.stringToStringList(eventConfig.getRewards(),"\\|");
            eventConfig.setRewardList(rewardList);
        }

        yqHotelQueueNum = StringUtils.stringToIntegerList(YQHOTEL_QUEUE_NUM,"\\|");

        buildingStudyTimeMap = tempBuildingStudyTimeMap;
        buildingEnterTimeMap = tempBuildingEnterTimeMap;

        buildingSeatMap = tempBuildingSeatMap;

        skillConfigMap = tmpYQHotelSkillConfigMap;
        counterConfigMap = tmpYQHotelCounterConfigMap;
        titleConfigMap = tmpYQHotelTitleConfigMap;
        beastConfigMap = tmpYQHotelBeastConfigMap;
        eventConfigMap = tmpYQHotelEventConfigMap;
        foodNameConfigList = tmpNameConfigList;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public int getActivityId() {
        return activityId;
    }

    public Map<Integer, Map<Integer, YqHotelSkillConfig>> getSkillConfigMap() {
        return skillConfigMap;
    }

    public Map<Integer, Map<Integer, YqHotelCounterConfig>> getCounterConfigMap() {
        return counterConfigMap;
    }

    public Map<Integer, YqHotelTitleConfig> getTitleConfigMap() {
        return titleConfigMap;
    }

    public Map<Integer, YqHotelBeastConfig> getBeastConfigMap() {
        return beastConfigMap;
    }

    public Map<Integer, YqHotelEventConfig> getEventConfigMap() {
        return eventConfigMap;
    }

    public Map<Integer, Long> getBuildingEnterTimeMap() {
        return buildingEnterTimeMap;
    }

    public Map<Integer, Long> getBuildingStudyTimeMap() {
        return buildingStudyTimeMap;
    }

    public Map<Integer, Map<Integer, Integer>> getBuildingSeatMap() {
        return buildingSeatMap;
    }

    public int getEnrolBuildingId() {
        return enrolBuildingId;
    }

    public int getSoulCheckBuildingId() {
        return soulCheckBuildingId;
    }

    public int getYQHOTEL_SCORE_ITEM_ID() {
        return YQHOTEL_SCORE_ITEM_ID;
    }

    public int getYQHOTEL_COST_NUM_ID() {
        return YQHOTEL_COST_NUM_ID;
    }

    public String getYQHOTEL_QUEUE_NUM() {
        return YQHOTEL_QUEUE_NUM;
    }

    public Map<Integer, Long> getProcessTimeMap() {
        return processTimeMap;
    }

    public String getYQHOTEL_PROCESS_TIME() {
        return YQHOTEL_PROCESS_TIME;
    }

    public Map<Integer, Long> getWalkTimeMap() {
        return walkTimeMap;
    }

    public String getYQHOTEL_WALK_TIME() {
        return YQHOTEL_WALK_TIME;
    }

    public long getYQHOTEL_COUNTER_UNLOCK_TIME() {
        return YQHOTEL_COUNTER_UNLOCK_TIME;
    }

    public int getYQHOTEL_SKILL_NAME_NUM() {
        return YQHOTEL_SKILL_NAME_NUM;
    }

    public long getYQHOTEL_EVENT_REFRESH_TIME() {
        return YQHOTEL_EVENT_REFRESH_TIME;
    }

    public long getYQHOTEL_BATTLE_QUICK_OPEN_LIMIT() {
        return YQHOTEL_BATTLE_QUICK_OPEN_LIMIT;
    }

    public List<Integer> getYqHotelQueueNum() {
        return yqHotelQueueNum;
    }

    public List<YqHotelFoodNameConfig> getFoodNameConfigList() {
        return foodNameConfigList;
    }
}
